package com.emm.yixun.website.task.utils;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;

/**
 * EXCEL操作辅助类
 * @author ThinkPad
 *
 */
public class ExcelReader {
	 public static String getCell(Cell cell) {
		          String value = "";
		          if (cell != null) {
		              switch (cell.getCellType()) {
		              case Cell.CELL_TYPE_FORMULA:
		                  try {
		                      value = String.valueOf(cell.getNumericCellValue());
		                  } catch (IllegalStateException e) {
		                      value = String.valueOf(cell.getRichStringCellValue());
		                  }
		                 break;
		             case Cell.CELL_TYPE_NUMERIC:
		            	    if (HSSFDateUtil.isCellDateFormatted(cell)) {
	                            Date date = cell.getDateCellValue();
	                            if (date != null) {
	                                value = new SimpleDateFormat("yyyy-MM-dd").format(date);
	                            } else {
	                                value = null;
	                            }
	                         }else{
	                            value = new DecimalFormat("0.00").format(cell.getNumericCellValue());
	                         }
		                  break;
		              case Cell.CELL_TYPE_STRING:
		                  value = String.valueOf(cell.getRichStringCellValue());
		                 break;
		             }
		         }
		          return value;
	 }
	 public static boolean isNumeric(String str){ 
		 try {
			 Double.valueOf(str);
		} catch (Exception e) {
			return false;
		}
		   return true; 
		}
}
